#include "StdAfx.h"
#include "SudaFileOperation.h"

SudaFileOperation::SudaFileOperation(void)
{

}

SudaFileOperation::~SudaFileOperation(void)
{
}

int SudaFileOperation::ReadFileByRowEx(const CString& filePath,CStringArray& saveArray)
{
	saveArray.RemoveAll();
	CString line;
	try
	{
		if(!m_fileStdio.Open(filePath,CFile::modeRead | CFile::typeText))
			return FILE_READ_ERROR;
		while(m_fileStdio.ReadString(line))
		{
			saveArray.Add(line);
		}
	}
	catch(CFileException* e)
	{
		e->ReportError();
		e->Delete();
		m_fileStdio.Close();
	}

	m_fileStdio.Close();
	return FILE_READ_SUCCESS;
}

int SudaFileOperation::WriteFileByRow(const CString& filePath,CStringArray& saveArray)
{
	try
	{
		if(!m_fileStdio.Open(filePath,CFile::modeCreate | CFile::modeWrite | CStdioFileEx::modeWriteUnicode))
			return FILE_READ_ERROR;
		for(int i = 0; i < saveArray.GetSize(); i++)
		{
			m_fileStdio.WriteString(saveArray.GetAt(i));
			m_fileStdio.WriteString(CString(L"\r\n"));
		}
		
	}
	catch(CFileException* e)
	{
		e->ReportError();
		e->Delete();
		m_fileStdio.Close();
	}

	m_fileStdio.Close();
	return FILE_READ_SUCCESS;
}

